package es.ikex.servlet;

import java.io.File;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import es.ikex.dao.SliderDao;

/**
 * Servlet implementation class Slider
 */
@WebServlet("/Slider")
public class Slider extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int i = Integer.parseInt(request.getParameter("id"));
		SliderDao slider = new SliderDao();
		//"C:\\Tomcat7\\webapps\\Muebles\\img\\slider\\fotos\\"
		File ruta = new File( "/usr/local/tomcat/webapps/Muebles/img/slider/fotos/" + slider.getFoto(" where id = '"+ i + "'") );
		//File ruta = new File( "C:\\eclipse-jee-muebles\\WorkSpace\\Muebles\\WebContent\\img\\slider\\fotos\\" + slider.getFoto(" where id = '"+ i + "'") );
		ruta.delete();
		slider.modificarSlider(i, "sinFoto", "sinNombre", "sinEfecto");
		if(request.getParameter("editar") == null){
			request.getRequestDispatcher("/Admin/slider.jsp").forward(request, response);
		}
		else{
			request.setAttribute("id", i);
			request.getRequestDispatcher("/Admin/fotoSlider.jsp").forward(request, response);
		}
	}

}
